package com.news.controller;

import com.news.entity.News;
import com.news.entity.User;
import com.news.service.NewsService;
import com.news.service.NewsServiceImpl;
import com.news.service.UserService;
import com.news.service.UserServiceImpl;
import com.news.util.MD5Util;
import com.news.util.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet({})
public class NewsController extends HttpServlet {
/*
//        private static final long serialVersionUID = -596030381114687653L;
//
//        @Override
//        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            doPost(req, resp);
//        }
//
//        @Override
//        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.根据用户的路径判断用户的目的
//            String servletPath = req.getServletPath();
//            if(servletPath.contains("save")){
//                //新增
//                saveNews(req, resp);
//            }else if(servletPath.contains("edit")){
//                //更新
//                editUser(req, resp);
//            }else if(servletPath.contains("deleteUserBatch")){
//                //批量删除
//                deleteUserBatch(req, resp);
//            }else if(servletPath.contains("deleteUser")){
//                //单个删除
//                deleteUser(req, resp);
//            }else if(servletPath.contains("get")){
//                //单个查询
//                getUser(req, resp);
//            }else if(servletPath.contains("list")){
//                //批量查询，分页查询
//                listNews(req, resp);
//            }
//        }
//
//        private NewsService newsService = new NewsServiceImpl();
//
//        private void saveNews(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.获取数据
//            String name = req.getParameter("name");
//            String acct = req.getParameter("acct");
//            String pwd = req.getParameter("pwd");
//            //2.将数据封装到实体类对象
//            News news = new News();
//            news.setName(name);
//            news.setAcct(acct);
//            news.setPwd(MD5Util.getMD5(pwd));
//            //3.调用业务层
//            newsService.saveNews(news);
//            //4.跳转到查询
//            resp.sendRedirect("listUser.do");
//        }
//
//        private void editUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.获取数据
//            String id = req.getParameter("id");
//            String name = req.getParameter("name");
//            String pwd = req.getParameter("pwd");
//            //2.将数据封装到实体类对象
//            User user = new User();
//            user.setId(Integer.parseInt(id));
//            user.setName(name);
//            user.setPwd(MD5Util.getMD5(pwd));
//            //3.调用业务层
//            userService.editUser(user);
//            //4.跳转到查询
//            resp.sendRedirect("listUser.do");
//        }
//
//        private void deleteUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.获取数据
//            String id = req.getParameter("id");
//            //2.调用业务层
//            userService.removeUser(Integer.parseInt(id));
//            //3.跳转到查询
//            resp.sendRedirect("listUser.do");
//        }
//
//        private void deleteUserBatch(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.获取数据
//            String[] ids = req.getParameterValues("ids");
//            //2.调用业务层
//            userService.removeUserBatch(ids);
//            //3.跳转到查询
//            resp.sendRedirect("listUser.do");
//        }
//
//        private void getUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.获取数据
//            String id = req.getParameter("id");
//            //2.调用业务层
//            User user = userService.getUser(Integer.parseInt(id));
//            //3.将数据放置在域对象中
//            req.setAttribute("user", user);
//            //4.跳转
//            req.getRequestDispatcher("").forward(req, resp);
//        }
//
//        private void listNews(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            //1.获取数据
//            String pageNum = req.getParameter("pageNum")==null?"1":req.getParameter("pageNum");
//            String pageSize = req.getParameter("pageSize")==null?"0":req.getParameter("pageSize");
//            String name = req.getParameter("name");
//            //2.调用业务层
//            Page page = newsService.listNews(Integer.parseInt(pageNum), Integer.parseInt(pageSize), name);
//            //3.将数据放置在域对象中
//            req.setAttribute("news", page);
//            //4.跳转
//            req.getRequestDispatcher("page/ColumnManagement.jsp").forward(req, resp);
//        }
*/

}
